<template>
  <div v-loading="pageLoading" class="Bottom">
    <el-form ref="ruleForm" class="gl_form_mini form_label" :model="ranking" label-position="top">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+0" label="冠军" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model="ranking.paiming[0]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+6" label="第七名" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model.number="ranking.paiming[6]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+12" label="第十三名" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model.number="ranking.paiming[12]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+1" label="亚军" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model.number="ranking.paiming[1]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+7" label="第八名" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model.number="ranking.paiming[7]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+13" label="第十四名" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model.number="ranking.paiming[13]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+2" label="季军" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model.number="ranking.paiming[2]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+8" label="第九名" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model.number="ranking.paiming[8]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+14" label="第十五名" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model.number="ranking.paiming[14]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+3" label="第四名" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model.number="ranking.paiming[3]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+9" label="第十名" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model.number="ranking.paiming[9]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+15" label="第十六名" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model.number="ranking.paiming[15]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+4" label="第五名" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model.number="ranking.paiming[4]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+10" label="第十一名" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model.number="ranking.paiming[10]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+5" label="第六名" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model.number="ranking.paiming[5]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item :prop="'paiming.'+11" label="第十二名" class="gl_clear" :rules="{ required: true,message :'请输入',trigger:'blur'}">
            <el-input v-model.number="ranking.paiming[11]" class="gl_fl" style="width:60%" type="number" size="mini" placeholder="请输入" /><span class="count">分</span>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-button type="primary" class="Button" @click="submitForm('ruleForm')">确定</el-button>
  </div>
</template>

<script>
import { SiSTKWEventsManagementPlatformPointWeightGroupDto } from '@/lib/form/game/swaggerForm';
import { api_PUT_EventsManagementPointSettingPlatformPointSetting, api_GET_EventsManagementPointSettingPlatformPointSettingCompetitionLevelId } from '@/extend/api/gameswaggerApi/app';
// import { index } from 'pages';
export default {
  props: {
    activeTab: {
      type: String,
      default: ''
    },
    years: {
      type: Array,
      default() {
        return [];
      }
    },
    yearWeights: {
      type: Array,
      default() {
        return [];
      }
    },
    yearTime: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      flag: false,
      pageLoading: false,
      SiSTKWEventsManagementPlatformPointWeightGroupDto: new SiSTKWEventsManagementPlatformPointWeightGroupDto(),
      ranking: {
        paiming: []
      }
    };
  },
  watch: {
    activeTab: {
      immediate: true,
      handler(val) {
        this.getLevelId(val);
      }
    }
  },
  created() {},
  methods: {
    getLevelId(val) {
      this.pageLoading = true;
      this.SiSTKWEventsManagementPlatformPointWeightGroupDto.competitionLevelId = val;
      const shu = [];
      api_GET_EventsManagementPointSettingPlatformPointSettingCompetitionLevelId(this.SiSTKWEventsManagementPlatformPointWeightGroupDto.competitionLevelId).then((res) => {
        for (var i = 0; i < res.pointSettings.length; i++) {
          shu[i] = res.pointSettings[i].point;
        }
        this.$set(this.ranking, 'paiming', shu);
        this.pageLoading = false;
      });
    },
    // 提交
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.years.length === 0) {
            this.flag = true;
          }
          this.SiSTKWEventsManagementPlatformPointWeightGroupDto.pointSettings = [];
          this.SiSTKWEventsManagementPlatformPointWeightGroupDto.yearWeights = [];
          this.$refs[formName].validate((valid) => {
            if (valid) {
              if (this.yearTime[0] === undefined) {
                this.$message('输入积分计算时间');
                this.flag = false;
                return;
              }
              this.SiSTKWEventsManagementPlatformPointWeightGroupDto.startTime = this.yearTime[0].split('T')[0] + 'T00:00:00';
              this.SiSTKWEventsManagementPlatformPointWeightGroupDto.endTime = this.yearTime[1].split('T')[0] + 'T23:59:59';
              for (var i = 0; i < this.years.length; i++) {
                const json = {};
                this.SiSTKWEventsManagementPlatformPointWeightGroupDto.yearWeights.push(json);
                this.SiSTKWEventsManagementPlatformPointWeightGroupDto.yearWeights[i].year = this.years[i];
                if ((this.yearWeights[i] === '' || this.yearWeights[i] === undefined) && this.years[i] !== '') {
                  this.$message('输入权重信息');
                  this.flag = false;
                  return;
                } else {
                  this.flag = true;
                }
                this.SiSTKWEventsManagementPlatformPointWeightGroupDto.yearWeights[i].weight = parseFloat(this.yearWeights[i] * 100) / 10000;
              }
              for (var j = 0; j < this.ranking.paiming.length; j++) {
                const json = {};
                this.SiSTKWEventsManagementPlatformPointWeightGroupDto.pointSettings.push(json);
                this.SiSTKWEventsManagementPlatformPointWeightGroupDto.pointSettings[j].point = parseFloat(this.ranking.paiming[j]);
                this.SiSTKWEventsManagementPlatformPointWeightGroupDto.pointSettings[j].rank = j + 1;
                this.SiSTKWEventsManagementPlatformPointWeightGroupDto.pointSettings[j].sortOrder = j + 1;
              }
            } else {
              console.log('error submit!!');
              return false;
            }
          });
          if (this.flag) {
            api_PUT_EventsManagementPointSettingPlatformPointSetting(this.SiSTKWEventsManagementPlatformPointWeightGroupDto).then(res => {
              this.$message({
                // 添加成功！
                message: '提交成功！',
                type: 'success'
              });
            }, error => {
              const _msg = error.error.message || error.message;
              console.log(_msg);
              this.$message({ type: 'error', message: _msg });
              this.submitLoading = false;
            });
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
};
</script>

<style lang="scss" scoped>
p {
  font-size: 14px;
}
.Bottom{
  padding: 0px 10px 10px 10px;
  background: #ffffff;
  border-radius: 6px;
}
.BottomPailie{
  display: flex;
}
.Button{
  margin-top: 80px;
  margin-bottom: 40px;
  margin-left: 50%;
  transform: translateX(-50%);
}
.form_label.el-form--label-top .el-form-item__label {
  line-height: 22px;
  padding-bottom: 0;
}
.count {
  font-size: 14px;
  margin-left: 5px;
  font-family: PingFang SC, PingFang SC-Regular;
  font-weight: bold;
}
::v-deep.Select .el-input__inner{
  height:28px;
    }
::v-deep.Select .el-input__suffix {
  top: 5px;
    }
::v-deep input::-webkit-outer-spin-button,
::v-deep input::-webkit-inner-spin-button {
    -webkit-appearance: none!important;
  }
::v-deep input[type="number"]{
    -moz-appearance: textfield;
  }
</style>

